package com.wyd.utils;

import com.wyd.config.Constant;
import com.wyd.enums.WeightEnum;

import java.math.BigDecimal;

/**
 * 分数计算转换类
 */
public class ScoreUtils {
    /**
     * 根据不同的类型计算分数
     * @param type
     * @param score
     */
    public static int getScore(WeightEnum type,BigDecimal score) {
        int resultScore = 0;
        switch (type){
            case AVAILABILITY:
                int avail = score.multiply(new BigDecimal(100)).intValue();
                resultScore = avail * Constant.SROCE_MAX/1000;
                break;
            case COST:
                int cost = score.multiply(new BigDecimal(100)).intValue();
                resultScore = (Constant.SROCE_MAX - cost) <0 ? 0 : (Constant.SROCE_MAX - cost);
                break;
            case MTK:
                resultScore = (100-score.intValue()) * Constant.SROCE_MAX/1000;
                break;
            case NETWORK:
                resultScore = score.intValue() * Constant.SROCE_MAX/1000;
                break;
            case PRIORITY:
                resultScore = score.intValue() * Constant.SROCE_MAX/100;
                resultScore = resultScore > Constant.SROCE_MAX ? Constant.SROCE_MAX : resultScore;
                break;
            case PACKAGETYPE:
                resultScore = score.intValue() * Constant.SROCE_MAX/10;
                break;
        }
        return resultScore;
    }

    public static void main(String[] args) {
        System.out.println(getScore(WeightEnum.AVAILABILITY,new BigDecimal(0.26)));
        System.out.println(getScore(WeightEnum.COST,new BigDecimal(0.23)));
        System.out.println(getScore(WeightEnum.COST,new BigDecimal(20.26)));
        System.out.println(getScore(WeightEnum.MTK,new BigDecimal(2)));
        System.out.println(getScore(WeightEnum.NETWORK,new BigDecimal(23)));
        System.out.println(getScore(WeightEnum.PRIORITY,new BigDecimal(12)));
    }
}
